<?php

namespace app\common\services;

//只封装通用方法
use yii\helpers\Html;

class UtilService
{
    public static function getIP(){
        if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        return isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"]:'';
    }
    //放xss攻击
    public static function encode( $display){
        return Html::encode( $display );
    }

    //获取根目录
    public static function getRootPath(){
        return dirname( \Yii::$app->vendorPath );
    }

    //判断是否是微信登陆
    public static function isWechat(){
        $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
        if (strrpos($ua, 'micromessenger') !== false){ //micromessenger 微消息
            return true;
        }
        return false;
    }

}